package com.lzw.bluetoothpractice.Utils;

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;

/**
 * reference apache commons <a
 * href="http://commons.apache.org/codec/">http://commons.apache.org/codec/</a>
 * <p>
 * support MD2/MD5/SHA/SHA256/SHA384/SHA512
 *
 * @author Aub
 */
public class DigestUtils {

    public static String HMACSHA256(String data, String key) throws Exception {

        Mac sha256_HMAC = Mac.getInstance("HmacSHA256");

        SecretKeySpec secret_key = new SecretKeySpec(key.getBytes("UTF-8"), "HmacSHA256");

        sha256_HMAC.init(secret_key);

        byte[] array = sha256_HMAC.doFinal(data.getBytes("UTF-8"));


       return Base64Encoder.encode(array);

    }

}  